package com.situ.company.department.service.impl;

import java.util.List;

import com.situ.company.department.dao.IDepartmentDao;
import com.situ.company.department.dao.impl.DepartmentDao2Impl;
import com.situ.company.department.model.DepartmentModel;
import com.situ.company.department.service.IDepartmentService;
import com.situ.company.project.model.ProjectModel;

public class DepartmentServiceImpl implements IDepartmentService {

		private IDepartmentDao dao = new DepartmentDao2Impl();

		@Override
		public String insert(DepartmentModel model) {
			if(selectModel(model) ==null) {
				Integer res=dao.insert(model);
				return res==null?null:res.toString();
			}
			return "repeat";
		}

		@Override
		public String delete(DepartmentModel model) {
			Integer res=dao.delete(model);
			return res==null?null:res.toString();
		}
		@Override
		public Integer update(DepartmentModel model) {
			// TODO Auto-generated method stub
			return dao.updateAll(model);
		}

		@Override
		public List<DepartmentModel> selectList(DepartmentModel model) {
			// TODO Auto-generated method stub
			String code=model.getCode();
			model.setCode(code==null?"%":"%"+code+"%");
			String name=model.getName();
			model.setName(name==null?"%":"%"+name+"%");
			return dao.selectList(model);
		}

		@Override
		public DepartmentModel selectModel(DepartmentModel model) {
			// TODO Auto-generated method stub
			return dao.selectModel(new DepartmentModel(model.getCode()));
		}

		@Override
		public Integer selectCount(DepartmentModel model) {
			DepartmentModel m1=new DepartmentModel();
			String code=model.getCode();
			m1.setCode(code==null?"%":"%"+code+"%");
			String name=model.getName();
			m1.setName(name==null?"%":"%"+name+"%");
			return dao.selectCount(m1);
		}

		
}
